﻿using Microsoft.EntityFrameworkCore;
using SmartCity.Passport.Domain.Entities;

namespace SmartCity.Passport.Infrastructure
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class MyDbcontext : DbContext
    {
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="options">选项</param>
        public MyDbcontext(DbContextOptions options) : base(options)
        {
        }
        /// <summary>
        // 注册用户实体类
        /// </summary>
        public DbSet<User> Users { get; set; }
        /// <summary>
        /// 注册角色实体类
        /// </summary>
        public DbSet<Role> Roles { get; set; }
        /// <summary>
        /// 注册角色用户实体类
        /// </summary>
        public DbSet<RoleUser> RoleUsers { get; set; }
        /// <summary>
        /// 注册权限表
        /// </summary>
        public DbSet<Permission> Permissions { get; set; }
        /// <summary>
        /// 注册角色权限实体类
        /// </summary>
        public DbSet<RolePermission> rolePermissions { get; set; }

        /// <summary>
        /// 当模型正在创建时发生
        /// </summary>
        /// <param name="modelBuilder">模型建造</param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //强调没有主键的实体
            modelBuilder.Entity<RoleUser>().HasNoKey();
            modelBuilder.Entity<RolePermission>().HasNoKey();

        }
    }
}
